package com.mall.auth.service;

import cn.hutool.core.collection.CollUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author wuyijie
 * @description: TODO 资源服务。初始化的时候把资源与角色匹配关系缓存到Redis中，方便网关服务进行鉴权的时候获取
 * @date 2021/6/20 22:30
 */
@Service
public class ResourceServiceImpl {
    private Map<String, List<String>> resourceRolesMap;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @PostConstruct
    public void initData() {
        resourceRolesMap = new TreeMap<>();
        resourceRolesMap.put("get/applicationApi/application", CollUtil.toList("ADMIN"));
        resourceRolesMap.put("post/applicationApi/application", CollUtil.toList("ADMIN", "TEST"));
        redisTemplate.opsForHash().putAll("com/mall/auth", resourceRolesMap);
    }
}
